package com.ctshk.sapp.tour.controller;

import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.constant.ErrCode;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.enums.SystemError;
import com.ctshk.common.exception.BusinessException;
import com.ctshk.rpc.tour.req.UrlToPdfReq;
import com.ctshk.rpc.tour.service.HtmlToPdfService;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


@RestController
@RequestMapping("/html/to/pdf")
public class HtmlToPdfController {

    @DubboReference
    private HtmlToPdfService htmlToPdfService;

    @ApiOperation(value="获取PDF文件行程", notes="获取PDF文件行程")
    @OperationLogAnnotation(operModul = OperationLogModel.TOUR, operType = OperationLogType.OTHER, operTitle = "获取PDF文件行程", operDesc = "获取PDF文件行程")
    @PostMapping("/urlToPdf")
    public Result urlToPdf(@RequestBody @Valid UrlToPdfReq req) {
        String fileUrl = htmlToPdfService.urlToPdf(req.getUrl(), req.getOutputFileName());
        if(StringUtils.isBlank(fileUrl)){
            return Result.failed(SystemError.HTML_TO_PDF_FAILED);
        }
        return Result.success();
    }
}
